//
//  CodeLoginVM.swift
//  kxf
//   验证码登录
//  Created by Mac on 2024/3/4.
//

import Foundation
import UIKit

class CodeLoginVM: UIView {
    
    let selfHeight = kFitWidth(130)
    
    var getCodeBlock:(()->())?

    override init(frame:CGRect){
        super.init(frame: CGRect.init(x: 0, y: frame.origin.y, width: SCREEN_WIDHT, height: selfHeight))
        self.backgroundColor = .white
        self.isUserInteractionEnabled = true
        
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var phoneVm : LoginInputVM = {
        let vm = LoginInputVM.init(frame: CGRect.init(x: 0, y: kFitWidth(20), width: 0, height: 0))
        vm.textField.placeholder = "请输入手机号"
        vm.textField.keyboardType = .numberPad
        vm.maxLength = 11
        
        
        return vm
    }()
    lazy var codeVm : LoginInputVM = {
        let vm = LoginInputVM.init(frame: CGRect.init(x: 0, y: self.phoneVm.frame.maxY+kFitWidth(20), width: 0, height: 0))
        vm.textField.placeholder = "请输入验证码"
        vm.maxLength = 6
        vm.showCodeBtn()
        vm.getCodeBtn.addTarget(self, action: #selector(getCodeAction), for: .touchUpInside)
        
        return vm
    }()
}

extension CodeLoginVM{
    @objc func getCodeAction() {
        if self.getCodeBlock != nil{
            self.getCodeBlock!()
        }
    }
}
extension CodeLoginVM{
    func initUI() {
        addSubview(phoneVm)
        addSubview(codeVm)
//        codeVm.showCodeBtn()
    }
}
